<?php
/**
 * User: CQH
 * Date: 2017/8/26
 * Time: 14:20
 */
namespace app\common\model;

use think\Model;
use think\db;
use PHPExcel;
/*
 * 客户信息model--废弃
 */
class Customer extends Model
{
	protected $db;
	protected $op;
	protected $ad;
	protected $areas_db = 'areas';
	protected $pn;
    public $sdb_name = 'administrative_user';
    public $sdb_name_log = 'administrative_log';

	public function __construct()
	{
		$this->db = Db::name("Customer");
		$this->op = Db::name("Operation_info");
		$this->ad = Db::name("Administrative_info");
		$this->areas_db = Db::name('areas');
		$this->pn =  new PersonnelNumber();
	}

	/*
	 *  统计用户数量
	 *  @author ligang
	 *  @param  $where      条件
	 *  @param  $whereTime  时间条件['字段'=>'规则']
	 *  @return int
	 */
    public function CountUserNumber($where,$whereTime,$join=[])
    {
        if (empty($join)){
            if (empty($whereTime)){
                $result = $this->db->where($where)->count();
            }else{
                if (!is_array($whereTime)){
                    return "时间必须是数组,以键值对形式";
                }
                $whereTimeKey = array_keys($whereTime);
                $result = $this->db->where($where)->whereTime($whereTimeKey[0],$whereTime[$whereTimeKey[0]])->count();
            }
        }else{
            if (empty($whereTime)){
                $result = $this->db->where($where)->join($join)->count();
            }else{
                if (!is_array($whereTime)){
                    return "时间必须是数组,以键值对形式";
                }
                $whereTimeKey = array_keys($whereTime);
                $result = $this->db->join($join)->where($where)->whereTime($whereTimeKey[0],$whereTime[$whereTimeKey[0]])->count();
            }
        }
        return $result;
    }

	/**
	 * 客户记录增加一条数据(返回新增加的user_id)
	 * @param $data  ->  数组   ['key' => 'value']
	 * @return user_id
	 */
	public function insertOne($data)
	{
        $user_id = $this->db->insertGetId($data);
        // 判断结果 并返回
        if ($user_id == false) {
            return false;
        }
        return $user_id;
	}

	/**
	 * 按user_id主键删除一条数据（逻辑删除）
	 * @param $id
	 * @return $this|bool
	 */
	public function deleteOne($id,$status)
	{
		$result = $this->db->where(array('user_id'=>$id))->setField('account_status',$status);
		if ($result !== 1) {
			return false;
		}
		return $result;
	}

	/**
	 * 根据条件 $where修改一条数据
	 * @param $where ->  条件  ['key' => 'value']
	 * @param $data  ->  数据  ['key' => 'value', 'key' => 'value']
	 * @return $this|bool
	 */
    public function updateOne($where,$data)
    {
    	// 根据条件修改一条数据
    	$result = $this->db->where($where)->update($data);
    	// 判断结果 并返回数据
    	if ($result == false) {
    		return false;
    	}
    	return $result;
    }
    public function getOne($where,$field='*'){
        return $this->db->where($where)->field($field)->find();
    }
    /**
     * 根据条件 $where获取单条数据
     * @param $where  ->  数组  ['key' => 'value']
     * @return bool|false|\PDOStatement|string|\think\Collection
     */
    public function selectOne($where)
    {
    	$userInfo = $this->db->where($where)->find();
    	//获取客户配置信息
    	$status = config('account_status');
    	$nature = config('nature');
    	$housing_property = config('housing_property');
    	$is_entry = config('is_entry');
    	$user_type = config('user_type');
        if (!empty($userInfo)) {
            //转换客户配置信息状态
//            $userInfo['account_status'] = $status[$userInfo['account_status']];
            $userInfo['nature'] = $nature[$userInfo['nature']];
            $userInfo['housing_property'] = $housing_property[$userInfo['housing_property']];
            $userInfo['is_entry'] = $is_entry[$userInfo['is_entry']];
            $userInfo['user_type'] = $user_type[$userInfo['user_type']];
            $userInfo['add_time'] = empty($userInfo['add_time'])?'':date("Y-m-d H:i:s",$userInfo['add_time']);
            $userInfo['birthday'] = empty($userInfo['birthday'])?'':date("Y-m-d",$userInfo['birthday']);
        }
    	// 判断结果并返回
    	if ($userInfo == false) {
    		return false;
    	}
    	return $userInfo;
    }

    /**
     * 根据条件 $where获取单条数据       find
     * @param $where  ->  数组  ['key' => 'value']
     * @return bool|false|\PDOStatement|string|\think\Collection
     */
    public function findOne($where)
    {
    	$join = [
	    	['rq_operation_info','rq_operation_info.o_id = rq_customer.operation_id','left'],
	    	['rq_customer_administrative_center','rq_customer_administrative_center.user_id = rq_customer.user_id','left'],
	    	['rq_administrative_info','rq_administrative_info.a_id = rq_customer_administrative_center.administrative_id','left']
		];
    	$file = "rq_customer.*,
    			rq_operation_info.company_name as ocompany_name,
    			rq_administrative_info.company_name as acompany_name,
    			rq_administrative_info.a_id
    			";
    	$userInfo = $this->db->join($join)->where($where)->field($file)->find();
        // 判断结果并返回
        if ($userInfo == false) {
            return false;
        }
        if($userInfo['is_entry']==1){
            $pninfo =  $this->pn->where(array('personnel_number'=>$userInfo['employee_id']))->find();
            $userInfo['personnel_time'] = date("Y-m-d",$pninfo['personnel_time']);
        }else{
            $userInfo['personnel_time'] = '';
        }
        if($userInfo['is_entry']==3){
            $userInfo['departure_time'] = date("Y-m-d",$userInfo['departure_time']);
        }
    	//获取客户配置信息
    	$status = config('account_status');
    	$nature = config('nature');
    	$housing_property = config('housing_property');
    	$is_entry = config('is_entry');
    	$user_type = config('user_type');
    	//转换客户配置信息状态
//    	$userInfo['account_status'] = $status[$userInfo['account_status']];
    	$userInfo['nature'] = $nature[$userInfo['nature']];
    	$userInfo['housing_property'] = $housing_property[$userInfo['housing_property']];
        $userInfo['is_set_entry'] = $userInfo['is_entry'];
    	$userInfo['is_entry'] = $is_entry[$userInfo['is_entry']];
    	$userInfo['user_type'] = $user_type[$userInfo['user_type']];

    	$t = $userInfo['add_time'];
    	$birth = $userInfo['birthday'];

    	/* $dtime = $userInfo['departure_time'];
    	$userInfo['departure_time'] = date("Y-m-d",$dtime); */

    	$userInfo['add_time'] = date("Y-m-d H:i:s",$t);
    	$userInfo['birthday'] = date("Y-m-d",$birth);

    	return $userInfo;
    }

    /**
     * 获取所有 未被逻辑删除的数据
     * @return bool|false|\PDOStatement|string|\think\Collection
     */
    public function getList()
    {
    	$userInfo = $this->db->where(array('is_delete'=>0))->cache(true)->select();
    	// 判断结果 并返回
    	if ($userInfo == false) {
    		return false;
    	}
    	return $userInfo;
    }

    /**
     * 获取所有数据 (包含被逻辑删除的数据)
     * @return bool|false|\PDOStatement|string|\think\Collection
     */
    public function getListAll()
    {
    	$userInfo = $this->db->cache(true)->select();
    	// 判断结果 并返回
    	if ($userInfo == false) {
    		return false;
    	}
    	return $userInfo;
    }

    /**
     *    分页查询数据(不查询逻辑删除的数据)
     * @author CQH
     * @param array     $where                       AND查询条件
     * @param array     $whereOr                     OR查询条件
     * @return array
     * @return string|int    $data['currentPage']    获取当前页
     * @return string|int    $data['listRows']       每页显示数目
     * @return array         $data['data']           数据
     */
    public function selectPage($where=array(),$whereOr=array())
    {
    	//获取分页配置
        $currentPage = !empty($where['page'])?$where['page']:1;
        unset($where['page']);
        $Configuration = new Configuration();
        $listRows = intval($Configuration->getkey('pagesize'));
    	//关联查询
    	$join = [
            ['rq_operation_info','rq_operation_info.o_id = rq_customer.operation_id','left'],
            ['rq_customer_administrative_center','rq_customer_administrative_center.user_id = rq_customer.user_id','left'],
            ['rq_administrative_info','rq_administrative_info.a_id = rq_customer_administrative_center.administrative_id','left']
    	];
    	//限制查询（只查询没有被逻辑删除的数据）
//    	$where['rq_customer.is_delete'] = ['=',0];
    	//获取数据（对象）
    	$result = $this->db
            ->join($join)
            ->where($where)
            ->whereOr($whereOr)
    	    ->field('rq_customer.user_id,
                    rq_customer.avatar_img,
                    rq_customer.account,
                    rq_customer.username,
                    rq_customer.gender,
                    rq_customer.telphone,
                    rq_customer.user_class,
                    rq_customer.realname,
                    rq_customer.is_delete,
                    rq_customer.account_status,
                    rq_customer.add_time,
                    rq_customer.last_login_time,
                    rq_customer.add_mode,rq_customer.id_card,rq_customer.account
                    ')
    	    ->page($currentPage,$listRows)
            ->group('rq_customer.user_id')
            ->order('rq_customer.add_time desc')
            ->select();
        if(!empty($result)){
            foreach ($result as $k => $v) {
                $result[$k]['realname'] = empty($v['realname'])?'':$v['realname'];
                $result[$k]['id_card'] = empty($v['id_card'])?'':$v['id_card'];
                $result[$k]['account_status_name'] = $v['account_status']==1?'正常':'冻结';
            }
        }
    	$data = array();
    	//计算数据总数
    	$data['page']['count'] = $this->db->where($where)->join($join)->whereOr($whereOr)->count();
    	//获取当前页
    	$data['page']['currentPage'] = $currentPage;
    	//计算共有多少页
    	$data['page']['lastPage'] = intval(ceil($data['page']['count'] / $listRows));;
    	//每页显示数目
    	$data['page']['listRows'] = $listRows;

    	$data['data'] = $result;

    	return $data;
    }

    /**
     * 分页查询数据(不查询逻辑删除的数据)
     * @author CQH
     * @param array     $where                       AND查询条件
     * @param array     $join                        关联条件条件
     * @param string    $field                       查询字段
     * @param string    $order                       排序
     * @param string    $db                          数据库
     * @return array
     * @return string|int    $data['currentPage']    获取当前页
     * @return string|int    $data['listRows']       每页显示数目
     * @return array         $data['data']           数据
     */
    public function selectPages($where=array(),$join = [], $field = "*", $order, $db)
    {
        $this->db = Db::name($db);
        //获取分页配置
        $currentPage = !empty($where['page'])?$where['page']:1;
        unset($where['page']);
        $Configuration = new Configuration();
        $listRows = intval($Configuration->getkey('pagesize'));

        //限制查询（只查询没有被逻辑删除的数据）
        $where['rq_customer.is_delete'] = ['=',0];
        //获取数据（对象）
        $page = $this->db->join($join)->where($where)->field($field)
            ->page($currentPage,$listRows)->order($order)->select();
//        echo $this->db->getLastSql();
        $data = array();
        //计算数据总数
        $data['page']['count'] = $this->db->join($join)->where($where)->count();
        //获取当前页
        $data['page']['currentPage'] = $currentPage;
        //计算共有多少页
        $data['page']['lastPage'] = intval(ceil($data['page']['count'] / $listRows));;
        //每页显示数目
        $data['page']['listRows'] = $listRows;

        $data['data'] = $page;

        return $data;
    }

    /**
     * 获取所有省级承包商数据
     * @return array|bool
     */
    public function selectOperationInfo($where=array())
    {
    	$res = $this->op
            ->alias('op')
            //->join('rq_administrative_info ai','ai.operation = op.o_id')
            ->where($where)->field('op.o_id,op.company_name,op.province_name,op.province_id')->where(array('op.is_delete'=>0))->select();
    	return $res;
    }

    /**
     * 获取所有行政中心数据
     * @param $where    查询条件（一维数组）
     * @return array|bool
     */
	public function selectAdministrativeInfo($where=array())
    {
        $res = $this->ad->where($where)->where(array('is_delete'=>0))->field('province_id,city_id,a_id,company_name,area_name,area_id')->select();
        return $res;
        exit();
        //对多行政区域的处理
        $data = array();
        foreach ($res as $key => $value){
            if(strpos($value['area_name'],',') != false){
                $a_id = $value['a_id'];
                $company_name = $value['company_name'];
                $arr_area_name = explode(',',$value['area_name']);
                $arr_area_id = explode(',',$value['area_id']);
                foreach ($arr_area_name as $k=>$v){
                    $data[$k]['a_id'] = $a_id;
                    $data[$k]['company_name'] = $company_name;
                    $data[$k]['area_name'] = $v;
                    $data[$k]['area_id'] = $arr_area_id[$k];
                }
            }else{
                array_push($data,$value);
            }
        }
        //去除相同的区域
        $i = 0;
        foreach ($data as $kk => $vv){
            if ($i+1<count($data)){
                if (in_array($vv['a_id'],$data[$i+1])){
                    $i = 0;
                    array_splice($data, $kk, 1);
                }else{
                    $i++;
                }
            }
            continue;
        }
        return $data;
    }

    /*
     *  地址(省)
     * @param   array    $where    查询条件（一维数组）
     */
    public function areasProvince($where=array())
    {
    	$where['parent_id'] = 0;
    	//省
    	$province = $this->areas_db->where($where)->select();
    	return $province;
    }

    /*
     *  地址(市)
     */
    public function areasCity($province_id = '')
    {
    	//省
    	if (!empty($province_id)){
    		$where['parent_id'] = $province_id;
    	}else{
    		$where = '1=1';
    	}
    	$province = $this->areas_db->where($where)->select();
    	return $province;
    }

    /*
     *  地址(区/县)
     */
    public function areaName($city_id = '')
    {
    	if (!empty($city_id)){
    		$where['parent_id'] = $city_id;
    	}else{
    		$where = '1=1';
    	}
    	$areaName = $this->areas_db->where($where)->select();
    	return $areaName;
    }

    //验证数据
    public function valli($data){
//        $field = "";
//        // 检查字段是否为空
//        foreach ($data as $key => $value){
//            if (empty(trim($value))){
//                $field = $key;
//                break;
//            }
//        }
//        switch ($field){
//            case "realname":
//                return ['code' => 0, 'msg' => '客户姓名不能为空'];
//                break;
//            case "id_card":
//                return ['code' => 0, 'msg' => '身份证号不能为空'];
//                break;
//            case "telphone":
//                return ['code' => 0, 'msg' => '联系电话不能为空'];
//                break;
//        }
        if($data['realname'] == '') {
            return ['code' => 0, 'msg' => '客户姓名不能为空'];
        }
//        if($data['id_card'] == '') {
//            return ['code' => 0, 'msg' => '身份证号不能为空'];
//        }
        if(!empty($data['id_card']) && !checkIdCard($data['id_card'])){
            return array('code'=>0,'msg'=>'身份证格式不对');
        }
        if($data['telphone'] == '') {
            return ['code' => 0, 'msg' => '联系电话不能为空'];
        }
        if (!inge_ismobile($data['telphone'])){
            return array('code'=>0,'msg'=>'电话格式不正确');
        }
        if ($data['is_old_client'] == 1){
            if (empty($data['old_client_name'])){
                return array('code'=>0,'msg'=>'请输入老客户姓名');
            }
            if (empty($data['old_client_tel'])){
                return array('code'=>0,'msg'=>'请输入老客户电话');
            }
        }
        if (isset($data['operation_id']) && count($data['operation_id']) != count($data['a_id'])){
            return ['code' => 0, 'msg' => '请完善用户所属管理区域'];
        }
        if(empty($data['account_status'])) {
            return ['code' => 0, 'msg' => '账户状态不能为空'];
        }
        if (isset($data['operation_id']) && $data['operation_id'] == '') {
            return ['code' => 0, 'msg' => '请选择省级承包商'];
        }
        if (isset($data['a_id']) && $data['a_id'] == '') {
            return ['code' => 0, 'msg' => '请选择行政区域'];
        }
//        if ($data['province_code'] == '0') {
//            return ['code' => 0, 'msg' => '请选择省份'];
//        }
//        if ($data['city_code'] == '0') {
//            return ['code' => 0, 'msg' => '请选择城市'];
//        }
//        if ($data['area_code'] == '0') {
//            return ['code' => 0, 'msg' => '请选择区/县'];
//        }
//        if(!trim($data['user_address'])){
//            return array('code'=>0,'msg'=>'用户详细地址不能为空');
//        }
        return true;
    }

    /**
     * @param $where
     * @param $nowPage
     * @param $limits
     * @param $field
     * @return false|\PDOStatement|string|\think\Collection
     *          获取所有用户
     */
    public function getAll($where, $nowPage = '', $limits = '', $field = '*', $dbName = 'rq_customer_administrative_center', $join = '', $order = 'a.user_id desc')
    {

        $data = Db::table($dbName)           // 主表
            ->alias('a')               // 主表别名
            ->join($join)                    // 需要关联的表
            ->field($field)                  // 需要查询的字段
            ->where($where)                  // 条件
            ->page($nowPage,$limits)         // 开始位置，多少数据
            ->order($order)
            ->select();
//        echo Db::table($dbName)->getLastSql();die();
        // 返回
        return $data;

    }

    /**
     * @param $where
     * @return int|string
     *       根据条件，获取用户数据数量
     */
    public function getCount($where, $join = '', $field = '*', $dbName = 'rq_customer_administrative_center')
    {

        $count = Db::table($dbName)                   // 主表
                ->alias('a')                    // 主表别名
                ->join($join)                         // 需要关联的表
                ->field($field)                       // 需要查询的字段
                ->where($where)                       // 条件
                ->count();

        // 返回
        return $count;

    }

    /**
     * @param array $where
     * @param string $nowPage
     * @param string $limits
     * @param string $field
     * @param string $dbName
     * @return false|\PDOStatement|string|\think\Collection
     *         单表获取所有用户
     */
    public function getAllUser($where = [], $nowPage = '', $limits = '', $field = '*', $dbName = 'rq_customer')
    {

        $data = Db::table($dbName)           // 主表
            ->field($field)                  // 需要查询的字段
            ->where($where)                  // 条件
            ->page($nowPage,$limits)         // 开始位置，多少数据
            ->select();
        // 返回
        return $data;

    }

    // 查询用户数量
    public function getCountUser($where=[], $field = '*', $dbName = 'rq_customer')
    {
        $count = Db::table($dbName)                   // 主表
                ->field($field)                       // 需要查询的字段
                ->where($where)                       // 条件
                ->count();
        // 返回
        return $count;
    }


    /*
     *  寻找上家
     * @param $id 当前合同推荐人ID
     * @param $star 当前合同人ID
     * @return array
     */
    public function seekPushPeople($id, $star, &$result = [])
    {
        //id推荐人ID
        $filed = '
           contract_id,
           introducer_id,
           user_id
        ';
        $data = Db::name('contract')->where(['user_id'=>$id])->field($filed)->find();
        if (!empty($data) && $data['introducer_id'] != $star){
            $result[] = $data;
            foreach ($result as $key=>$value){
                if ($data['introducer_id'] == $value['user_id']){
                    return $result;
                }
            }
            $this->seekPushPeople($data['introducer_id'],$star, $result);
        }
        return $result;
    }

    /*
     *  对某字段自增值
     *  @param array $where
     *  @param string $filed
     *  @param int $step
     */
    public function incTeamEquipmentNumber($where, $filed, $step = 1)
    {
        Db::name('test')->where($where)->setInc($filed, $step);
    }

    /**
    *  用户数据通过Excel 导入公共方法
    *  @auther 蒙明然
    */
    public function addOldUser($file)
    {
         // 判断文件是什么格式
        $type = pathinfo($file);
        $type = strtolower($type["extension"]);
        $type=$type==='Excel5' ? $type : 'Excel2007';
        ini_set('max_execution_time', '0');
        Vendor('phpexcel.phpexcel.Classes.PHPExcel');
        // 判断使用哪种格式
        $objReader = \PHPExcel_IOFactory::createReader($type);
        $objPHPExcel = $objReader->load($file);
        $sheet = $objPHPExcel->getSheet(0);
        // 取得总行数
        $highestRow = $sheet->getHighestRow();
        // 取得总列数
        $highestColumn = $sheet->getHighestColumn();
        //dump($highestColumn);

        //循环读取excel文件,读取一条,插入一条
        $data=array();
        //从第一行开始读取数据
        for($j=1;$j<=$highestRow;$j++){
            //从A列读取数据
            for($k='A';$k<='S';$k++){
                // 读取单积分格
                $data[$j][]=$objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
            }
        }
        foreach ($data as $k=>$v){
            if($v[0]==''){
                unset($data[$k]);
            }
        }
        return $data;
    }

    // 单条查询
    public function one($where, $field = '*')
    {
        $result = $this->db->where($where)->field($field)->find();
        return $result;
    }

    /**
     *    分页查询数据(不查询逻辑删除的数据)
     * @param array $where     AND查询条件
     * @param array $whereOr   OR查询条件
     * @return array
     * @throws \think\exception\DbException
     * @throws db\exception\DataNotFoundException
     * @throws db\exception\ModelNotFoundException
     */
    public function selectPageSize($where=array(),$whereOr=array())
    {
        // 获取分页配置
        $currentPage = !empty($where['page'])?$where['page']:1;
        unset($where['page']);
        $Configuration = new Configuration();
        $listRows = intval($Configuration->getkey('pagesize')) ?? 10;

        // 连表
        $join = [
            ['customer_administrative_center cac','a.user_id = cac.user_id','left']
        ];
        $field = 'a.user_id,a.account,a.add_time,a.username,a.gender,a.telphone,a.last_login_time,a.add_mode,
                  a.user_class,a.realname,a.account_status,a.avatar_img,a.operation_id,a.is_delete,a.is_auth,
                  cac.administrative_id';
        //限制查询（只查询没有被逻辑删除的数据）
//        $where['rq_customer.is_delete'] = ['=',0];

        if (!empty($where['cac.administrative_id']) && $where['cac.administrative_id'] == 2) {
            unset($where['cac.administrative_id']);
            //获取数据（对象）
            $page = Db::name('test')
                ->alias('a')
                ->join($join)
                ->where($where)
                ->whereOr($whereOr)
                ->whereNull('cac.administrative_id')
                ->field($field)
                ->page($currentPage,$listRows)
                ->order('a.add_time desc')
                ->select();
            $data = array();
            // 数量查询
            $data['page']['count'] = Db::name('test')->alias('a')->join($join)->where($where)->whereOr($whereOr)->whereNull('cac.administrative_id')->count();
        } else {
            // 获取数据（对象）
            $page = Db::name('test')
                ->alias('a')
                ->join($join)
                ->where($where)
                ->whereOr($whereOr)
                ->field($field)
                ->page($currentPage,$listRows)
                ->group('a.user_id')
                ->order('a.add_time desc')
                ->select();
            $data = array();
            // 数量查询
            $data['page']['count'] = Db::name('test')->alias('a')->join($join)->where($where)->whereOr($whereOr)->count();
        }

        // 获取当前页
        $data['page']['currentPage'] = $currentPage;
        // 计算共有多少页
        $data['page']['lastPage'] = intval(ceil($data['page']['count'] / $listRows));;
        // 每页显示数目
        $data['page']['listRows'] = $listRows;

        $data['data'] = $page;

        return $data;
    }


    // 连表查询用户列表
    public function getJoinAll($where, $join, $currentPage, $listRows, $field, $order)
    {
        //获取数据（对象）
        $data = Db::name('test')
                    ->alias('a')
                    ->join($join)
                    ->where($where)
                    ->field($field)
                    ->page($currentPage,$listRows)
                    ->group('a.user_id')
                    ->order($order)
                    ->select();
        return $data;
    }

    // 连表查询用户数量
    public function getJoinCount($where, $join)
    {
        $count = Db::name('test')
            ->alias('a')
            ->join($join)
            ->where($where)
            ->count();
        return $count;
    }




    // debug 不着急删
    public function selectPageSizes($where=array(),$whereOr=array())
    {
        //获取分页配置
        $currentPage = !empty($where['page'])?$where['page']:1;
        unset($where['page']);
        $Configuration = new Configuration();
        $listRows = intval($Configuration->getkey('pagesize'));
        //关联查询
//        $join = [
//            ['rq_operation_info','rq_operation_info.o_id = rq_customer.operation_id','left'],
//            ['rq_customer_administrative_center','rq_customer_administrative_center.user_id = rq_customer.user_id','left'],
//            ['rq_administrative_info','rq_administrative_info.a_id = rq_customer_administrative_center.administrative_id','left']
//        ];
        //限制查询（只查询没有被逻辑删除的数据）
//        $where['rq_customer.is_delete'] = ['=',0];
        //获取数据（对象）
        $page = $this->db
//            ->join($join)
            ->where($where)
            ->whereOr($whereOr)
            ->field('user_id,account,add_time,username,gender,telphone,last_login_time,add_mode,
                    user_class,realname,account_status,avatar_img,operation_id,is_delete,is_auth')
            ->page($currentPage,$listRows)
            ->order('rq_customer.add_time desc')
            ->select();
//    	echo $this->db->getLastSql();die();
        $data = array();
        //计算数据总数
        $data['page']['count'] = $this->db->where($where)->whereOr($whereOr)->count();
        //获取当前页
        $data['page']['currentPage'] = $currentPage;
        //计算共有多少页
        $data['page']['lastPage'] = intval(ceil($data['page']['count'] / $listRows));;
        //每页显示数目
        $data['page']['listRows'] = $listRows;

        $data['data'] = $page;

        return $data;
    }

}
